package framework;

import java.util.List;

import framework.input.AccelerometerInput;
import framework.input.MultiTouchScreenInput;
import framework.input.SingleTouchScreenInput;
import framework.input.TouchScreenInput;

import android.content.Context;
import android.os.Build.VERSION;
import android.view.View;

/**
 * Classe que gerencia todo parte de entrada de dados. Os métodos são
 * auto-explanatórios
 */
public class Input {
	AccelerometerInput accelerometer;
	TouchScreenInput touchScreen;

	public static class TouchEvent {
		public static final int TOUCH_DOWN = 0;
		public static final int TOUCH_UP = 1;
		public static final int TOUCH_DRAGGED = 2;

		public int type;
		public int x, y;
		public int pointer;
	}

	/**
	 * O fator de escala serve para lidar com diferentes resoluções de tela
	 * transformed touch x = real touch x * (target pixels on x axis / real
	 * pixels on x axis) transformed touch y = real touch y * (target pixels on
	 * y axis / real pixels on y axis)
	 * 
	 * @param context
	 * @param view
	 * @param scaleX
	 * @param scaleY
	 */
	public Input(Context context, View view, float scaleX, float scaleY) {
		accelerometer = new AccelerometerInput(context);
		if (Integer.parseInt(VERSION.SDK) < 5)
			touchScreen = new SingleTouchScreenInput(view, scaleX, scaleY);
		else
			touchScreen = new MultiTouchScreenInput(view, scaleX, scaleY);
	}

	public int getTouchX(int pointer) {
		return touchScreen.getTouchX(pointer);
	}

	public int getTouchY(int pointer) {
		return touchScreen.getTouchY(pointer);
	}

	public float getAccelX() {
		return accelerometer.getX();
	}

	public float getAccelY() {
		return accelerometer.getY();
	}

	public float getAccelZ() {
		return accelerometer.getZ();
	}

	public List<TouchEvent> getTouchEvents() {
		return touchScreen.getTouchEvents();
	}
}
